using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_BookingList : PagedControl
{
    public override string RequestString
    {
        get 
        {
            if (Request["search"] != null) return "Default.aspx?ctrl=booking_list&search=" + Request["search"] + "&page=";
            return "Default.aspx?ctrl=booking_list&page="; 
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ActiveAccording = "booking";
        p = Request["page"];
        totals = 0;
        currentPage = GetPageNumber(p);
        LoadData();
    }
    public void LoadData()
    {
        BookingDAO daoBooking=new BookingDAO();
        string str=(Request["search"]==null?"":Request["search"]);
        str="%"+str+"%";
        dgrBooking.DataSource = daoBooking.GetBookings(currentPage, pageSize, ref totals, str);
        dgrBooking.DataBind();
          
        lblPaging.Text = GetPageGrid(totals, pageSize, currentPage);
    }
    public string GetType(object type)
    {
        int t = int.Parse(type.ToString());
        if (t == 1) return "Tour package";
        else if (t == 2) return "Facility";
        else if (t == 3) return "Custom";
        else return "unknow";
    }
    public string GetState(object obj)
    {
        byte state = byte.Parse(obj.ToString());
        if (state == 0) return "Booked";
        else if (state == 1) return "Accepted";
        else if(state==2) return "Canceled";
        else return "undefined";
    }
    protected void dgrBooking_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        BookingDAO daoBooking=new BookingDAO();
        try
        {
            int id = int.Parse(dgrBooking.DataKeys[e.RowIndex].Value.ToString());
            if (daoBooking.Delete(id) > 0)
            {
                ShowMessage("Booking is deleted.");
            }
            else ShowMessage("Error. Specified booking cannot be deleted");
            LoadData();
        }
        catch (Exception ex)
        {
            ShowMessage("Error");
        }
    }

    /// <summary>
    /// Return request string for search in list page
    /// </summary>
    public string GetSearchRequest()
    {
        if (Request["search"] != null) return Request["search"];
        return "";
    }
}
